<template>
	<dt-main-body v-model="labelPosition">
		<div class="location">
			<el-breadcrumb separator-class="el-icon-arrow-right">
				<el-breadcrumb-item>
					<i class="iconfont icon-home"></i>
					管理中心
				</el-breadcrumb-item>
				<el-breadcrumb-item>商城管理</el-breadcrumb-item>
				<el-breadcrumb-item>查看订单</el-breadcrumb-item>
			</el-breadcrumb>
		</div>

		<div class="content-box">
			<el-tabs v-model="activeName" type="card">
				<el-tab-pane label="基本信息" name="info">
					<div class="tab-content">
						<el-row>
							<el-table :data="model.orderGoods" border class="table-form">
								<el-table-column label="商品名称" min-width="220">
									<template slot-scope="scope">
										<el-image class="pic" fit="contain" :src="$api.loadFile(scope.row.imgUrl)">
											<div slot="error" class="image-slot">
												<i class="el-icon-picture-outline"></i>
											</div>
										</el-image>
										<h4>{{scope.row.goodsTitle}}</h4>
										<span class="date">
											{{scope.row.goodsNo}}
										</span>
									</template>
								</el-table-column>
								<el-table-column label="规格" min-width="120">
									<template slot-scope="scope">
										<span class="nowrap">{{scope.row.skuText}}</span>
									</template>
								</el-table-column>
								<el-table-column prop="goodsPrice" label="商品原价" width="90"></el-table-column>
								<el-table-column prop="realPrice" label="实际价格" width="90"></el-table-column>
								<el-table-column prop="quantity" label="商品数量" width="80"></el-table-column>
								<el-table-column label="状态" width="80" align="center">
									<template slot-scope="scope">
										<el-tag size="small" type="success" effect="dark" v-if="scope.row.deliveryStatus==1">已发货</el-tag>
										<el-tag size="small" type="info" effect="dark" v-else-if="scope.row.deliveryStatus==2">已退货</el-tag>
										<el-tag size="small" type="danger" effect="dark" v-else>待发货</el-tag>
									</template>
								</el-table-column>
							</el-table>
						</el-row>
						<el-row v-if="model.orderPromotion.length>0">
							<el-table :data="model.orderPromotion" border class="table-form mat-20">
								<el-table-column prop="promotion.title" label="参与的促销活动" min-width="220"></el-table-column>
								<el-table-column prop="promotion.condition" label="消费额度" width="90"></el-table-column>
								<el-table-column label="奖励类型" width="90">
									<template slot-scope="scope">
										<el-tag size="small" effect="dark" v-if="scope.row.promotion.awardType==1">阶梯满减</el-tag>
										<el-tag size="small" type="success" effect="dark" v-else-if="scope.row.promotion.awardType==2">折扣</el-tag>
										<el-tag size="small" type="'warning" effect="dark" v-else-if="scope.row.promotion.awardType==3">送积分</el-tag>
										<el-tag size="small" type="danger" effect="dark" v-else-if="scope.row.promotion.awardType==4">送优惠券</el-tag>
										<el-tag size="small" type="success" effect="dark" v-else-if="scope.row.promotion.awardType==5">赠品</el-tag>
										<el-tag size="small" type="info" effect="dark" v-else>免运费</el-tag>
									</template>
								</el-table-column>
								<el-table-column prop="promotion.endTime" label="结束时间" width="160"></el-table-column>
							</el-table>
						</el-row>
						<el-row v-if="couponList.length>0">
							<el-table :data="couponList" border class="table-form mat-20">
								<el-table-column prop="shopCoupon.title" label="使用的优惠券" min-width="220"></el-table-column>
								<el-table-column label="类型" width="90">
									<template slot-scope="scope">
										<el-tag size="small" effect="dark" v-if="scope.row.shopCoupon.useType==1">商品券</el-tag>
										<el-tag size="small" effect="dark" v-else>店铺券</el-tag>
									</template>
								</el-table-column>
								<el-table-column prop="shopCoupon.minAmount" label="门槛(元)" width="90"></el-table-column>
								<el-table-column prop="shopCoupon.amount" label="面额(元)" width="90"></el-table-column>
								<el-table-column prop="useTime" label="使用时间" width="160"></el-table-column>
							</el-table>
						</el-row>
						<el-row class="card-form">
							<el-col :xs="24" :sm="12">
								<el-card shadow="hover">
									<div slot="header" class="clearfix">
										<i class="el-icon-s-goods"></i>
										<span>订单信息</span>
									</div>
									<div class="dl-box">
										<dl>
											<dt>订单号</dt>
											<dd>{{model.orderNo}}</dd>
										</dl>
										<dl>
											<dt>订单类型</dt>
											<dd>
												<span v-if="model.orderType==1">抢购订单</span>
												<span v-else-if="model.orderType==2">商品预售</span>
												<span v-else-if="model.orderType==3">积分换购</span>
												<span v-else>普通订单</span>
											</dd>
										</dl>
										<dl>
											<dt>支付状态</dt>
											<dd>
												<span v-if="model.paymentStatus==1">部分已付</span>
												<span v-if="model.paymentStatus==2">全额已付</span>
												<span v-else>待支付</span>
											</dd>
										</dl>
										<dl>
											<dt>配送状态</dt>
											<dd>
												<span v-if="model.deliveryStatus==1">全部发货</span>
												<span v-else-if="model.deliveryStatus==2">部分发货</span>
												<span v-else>待发货</span>
											</dd>
										</dl>
										<dl>
											<dt>订单进度</dt>
											<dd>
												<span v-if="model.refundStatus==1">全部退款</span>
												<span v-else-if="model.refundStatus==2">部分退款</span>
												<span v-else-if="model.status==1">等待付款</span>
												<span v-else-if="model.status==2">等待发货</span>
												<span v-else-if="model.status==3">等待收货</span>
												<span v-else-if="model.status==4">签收完成</span>
												<span v-else-if="model.status==5">交易完成</span>
												<span v-else-if="model.status==6">订单取消</span>
												<span v-else-if="model.status==7">订单作废</span>
											</dd>
										</dl>
										<dl>
											<dt>是否保价</dt>
											<dd>
												<span v-if="model.isInsure==1">是</span>
												<span v-else>否</span>
											</dd>
										</dl>
										<dl>
											<dt>保价金额</dt>
											<dd>
												{{model.insurePrice}} 元
											</dd>
										</dl>
										<dl>
											<dt>下单时间</dt>
											<dd>
												{{model.addTime}}
											</dd>
										</dl>
									</div>
								</el-card>
							</el-col>
							<el-col :xs="24" :sm="12">
								<el-card shadow="hover">
									<div slot="header" class="clearfix">
										<i class="el-icon-s-data"></i>
										<span>金额统计</span>
									</div>
									<div class="dl-box">
										<dl>
											<dt>应付商品总额</dt>
											<dd>{{model.payableAmount}} 元</dd>
										</dl>
										<dl>
											<dt>实付商品总额</dt>
											<dd>{{model.realAmount}} 元</dd>
										</dl>
										<dl>
											<dt>应付总运费</dt>
											<dd>{{model.payableFreight}} 元</dd>
										</dl>
										<dl>
											<dt>实付总运费</dt>
											<dd>{{model.realFreight}} 元</dd>
										</dl>
										<dl>
											<dt>优惠券金额</dt>
											<dd>-{{model.couponAmount}} 元</dd>
										</dl>
										<dl>
											<dt>促销优惠金额</dt>
											<dd>-{{model.promotionAmount}} 元</dd>
										</dl>
										<dl>
											<dt>订单优惠金额</dt>
											<dd>-{{model.discountAmount}} 元</dd>
										</dl>
										<dl>
											<dt>订单总金额</dt>
											<dd>{{model.orderAmount}} 元</dd>
										</dl>
									</div>
								</el-card>
							</el-col>
							<el-col :xs="24" :sm="12">
								<el-card shadow="hover">
									<div slot="header" class="clearfix">
										<i class="el-icon-truck"></i>
										<span>配送信息</span>
									</div>
									<div class="dl-box">
										<dl>
											<dt>配送方式</dt>
											<dd>{{model.delivery.title}}</dd>
										</dl>
										<dl>
											<dt>费用类型</dt>
											<dd>
												<span v-if="model.delivery.priceType==1">指定地址</span>
												<span v-else>统一费用</span>
											</dd>
										</dl>
										<dl>
											<dt>首重价格</dt>
											<dd>{{model.delivery.firstPrice}} 元 / {{model.delivery.firstWeight}} kg</dd>
										</dl>
										<dl>
											<dt>续重价格</dt>
											<dd>{{model.delivery.secondPrice}} 元 / {{model.delivery.secondWeight}} kg</dd>
										</dl>
										<dl>
											<dt>支持保价</dt>
											<dd>
												<span v-if="model.delivery.isInsure==1">支持</span>
												<span v-else>不支持</span>
											</dd>
										</dl>
										<dl>
											<dt>最低保额</dt>
											<dd>{{model.delivery.insurePrice}} 元</dd>
										</dl>
										<dl>
											<dt>保价费率</dt>
											<dd>{{model.delivery.insureRate}} ‰</dd>
										</dl>
									</div>
								</el-card>
							</el-col>
							<el-col :xs="24" :sm="12">
								<el-card shadow="hover">
									<div slot="header" class="clearfix">
										<i class="el-icon-location"></i>
										<span>收货信息</span>
									</div>
									<div class="dl-box">
										<dl>
											<dt>会员账户</dt>
											<dd>{{model.userName}}</dd>
										</dl>
										<dl>
											<dt>收货人姓名</dt>
											<dd>{{model.acceptName}}</dd>
										</dl>
										<dl>
											<dt>手机号码</dt>
											<dd>{{model.mobile}} </dd>
										</dl>
										<dl>
											<dt>固定电话</dt>
											<dd>{{model.telPhone}}</dd>
										</dl>
										<dl>
											<dt>送货地址</dt>
											<dd>{{model.address}}</dd>
										</dl>
										<dl>
											<dt>收货时间</dt>
											<dd>{{model.acceptTime}}</dd>
										</dl>
										<dl>
											<dt>用户留言</dt>
											<dd>{{model.postscript}}</dd>
										</dl>
									</div>
								</el-card>
							</el-col>
						</el-row>

					</div>
				</el-tab-pane>
				<el-tab-pane label="收款和售后" name="service">
					<div class="tab-content">
						<el-row>
							<el-table :data="model.collectionRelations" border class="table-form txt">
								<el-table-column type="expand">
									<template slot-scope="scope">
										<el-descriptions size="small" class="desctable">
											<el-descriptions-item label="开始付款时间">{{scope.row.collection.startTime}}</el-descriptions-item>
											<el-descriptions-item label="付款失效时间">{{scope.row.collection.endTime}}</el-descriptions-item>
											<el-descriptions-item v-if="scope.row.collection.status==2" label="完成时间">{{scope.row.collection.completeTime}}</el-descriptions-item>
											<el-descriptions-item v-if="scope.row.collection.remark" label="备注">{{scope.row.collection.remark}}</el-descriptions-item>
										</el-descriptions>
									</template>
								</el-table-column>
								<el-table-column prop="collection.tradeNo" label="交易号" min-width="190"></el-table-column>
								<el-table-column label="支付方式" width="120">
									<template slot-scope="scope">
										<span class="nowrap">{{scope.row.collection.paymentTitle}}</span>
									</template>
								</el-table-column>
								<el-table-column label="收款类型" width="90">
									<template slot-scope="scope">
										<span v-if="scope.row.collection.collectionType==1">预付款</span>
										<span v-else-if="scope.row.collection.collectionType==2">尾款</span>
										<span v-else>全款</span>
									</template>
								</el-table-column>
								<el-table-column prop="collection.paymentAmount" label="付款金额" width="90"></el-table-column>
								<el-table-column prop="collection.addTime" label="下单时间" width="180"></el-table-column>
								<el-table-column label="状态" width="90">
									<template slot-scope="scope">
										<el-tag size="small" effect="dark">
											{{checkPaymentStatus(scope.row.collection.status, scope.row.collection.startTime, scope.row.collection.endTime)}}
										</el-tag>
									</template>
								</el-table-column>
							</el-table>
						</el-row>
						<el-row class="mat-20">
							<el-table :data="orderRefundList" border class="table-form">
								<el-table-column prop="applyReason" label="退款原因" min-width="150" show-overflow-tooltip>
									<template slot-scope="scope">
										<span v-if="scope.row.applyReason">{{scope.row.applyReason}}</span>
										<span v-else>暂无备注</span>
									</template>
								</el-table-column>
								<el-table-column prop="refundAmount" label="退款金额" width="90"></el-table-column>
								<el-table-column prop="applyTime" label="申请时间" width="180"></el-table-column>
								<el-table-column prop="handleStatus" label="处理状态" width="90">
									<template slot-scope="scope">
										<el-tag size="small" effect="dark" v-if="scope.row.handleStatus==0">申请中</el-tag>
										<el-tag size="small" type="success" effect="dark" v-else-if="scope.row.handleStatus==3">已完成</el-tag>
										<el-tag size="small" type="info" effect="dark" v-else-if="scope.row.handleStatus==4">已拒绝</el-tag>
									</template>
								</el-table-column>
							</el-table>
						</el-row>
						<el-row class="mat-20">
							<el-table :data="orderExchangeList" border class="table-form">
								<el-table-column prop="applyReason" label="换货原因" min-width="150" show-overflow-tooltip>
									<template slot-scope="scope">
										<span v-if="scope.row.applyReason">{{scope.row.applyReason}}</span>
										<span v-else>暂无备注</span>
									</template>
								</el-table-column>
								<el-table-column prop="applyTime" label="申请时间" width="180"></el-table-column>
								<el-table-column prop="handleStatus" label="处理状态" width="90">
									<template slot-scope="scope">
										<el-tag size="small" effect="dark" v-if="scope.row.handleStatus==0">申请中</el-tag>
										<el-tag size="small" type="danger" effect="dark" v-else-if="scope.row.handleStatus==1">待买家发货</el-tag>
										<el-tag size="small" type="warning" effect="dark" v-else-if="scope.row.handleStatus==2">待卖家发货</el-tag>
										<el-tag size="small" type="success" effect="dark" v-else-if="scope.row.handleStatus==3">已完成</el-tag>
										<el-tag size="small" type="info" effect="dark" v-else-if="scope.row.handleStatus==4">已拒绝</el-tag>
									</template>
								</el-table-column>
							</el-table>
						</el-row>
					</div>
				</el-tab-pane>
				<el-tab-pane label="发货记录" name="delivery">
					<div class="tab-content">
						<el-table :data="orderDeliveryList" border class="table-form txt">
							<el-table-column prop="acceptName" label="收货人" width="100"></el-table-column>
							<el-table-column prop="express.title" label="快递名称" width="120"></el-table-column>
							<el-table-column prop="expressCode" label="快递单号" width="140" show-overflow-tooltip></el-table-column>
							<el-table-column label="备注" min-width="150" show-overflow-tooltip>
								<template slot-scope="scope">
									<span v-if="scope.row.remark">{{scope.row.remark}}</span>
									<span v-else>暂无备注</span>
								</template>
							</el-table-column>
							<el-table-column prop="addTime" label="发货时间" width="160"></el-table-column>
						</el-table>
					</div>
				</el-tab-pane>
				<el-tab-pane label="订单日志" name="log">
					<div class="tab-content">
						<el-table :data="model.orderLog" border class="table-form txt">
							<el-table-column prop="actionType" label="操作类型" width="90"></el-table-column>
							<el-table-column label="备注说明" min-width="150" show-overflow-tooltip>
								<template slot-scope="scope">
									<span v-if="scope.row.remark">{{scope.row.remark}}</span>
									<span v-else>暂无备注</span>
								</template>
							</el-table-column>
							<el-table-column prop="addBy" label="操作人" width="90"></el-table-column>
							<el-table-column prop="addTime" label="操作时间" width="160"></el-table-column>
						</el-table>
					</div>
				</el-tab-pane>
			</el-tabs>
		</div>

		<el-dialog title="订单发货" :visible.sync="showDeliveryDialog" fullscreen>
			<div class="content-box side">
				<el-row class="mab-20" v-if="model.orderGoods">
					<el-table :data="model.orderGoods" border @selection-change="handleDeliveryChange" class="table-form">
						<el-table-column type="selection" :selectable="checkSelecGoods" width="45" align="center"></el-table-column>
						<el-table-column label="商品名称" min-width="220">
							<template slot-scope="scope">
								<el-image class="pic" fit="contain" :src="$api.loadFile(scope.row.imgUrl)">
									<div slot="error" class="image-slot">
										<i class="el-icon-picture-outline"></i>
									</div>
								</el-image>
								<h4>{{scope.row.goodsTitle}}</h4>
								<span class="date">
									{{scope.row.goodsNo}}
								</span>
							</template>
						</el-table-column>
						<el-table-column prop="specText" label="规格" min-width="120" show-overflow-tooltip></el-table-column>
						<el-table-column prop="realPrice" label="单价" width="80"></el-table-column>
						<el-table-column prop="quantity" label="数量" width="80"></el-table-column>
						<el-table-column label="状态" width="80" align="center">
							<template slot-scope="scope">
								<el-tag size="small" type="success" effect="dark" v-if="scope.row.deliveryStatus==1">已发货</el-tag>
								<el-tag size="small" type="info" effect="dark" v-else-if="scope.row.deliveryStatus==2">已退货</el-tag>
								<el-tag size="small" type="danger" effect="dark" v-else>待发货</el-tag>
							</template>
						</el-table-column>
					</el-table>
				</el-row>

				<el-card shadow="hover">
					<div slot="header" class="clearfix">
						<i class="el-icon-truck"></i>
						<span>收货信息</span>
					</div>
					<el-form ref="deliveryForm" :model="delivery" :rules="rules" :label-position="labelPosition" label-width="120px">
						<el-form-item prop="acceptName" label="收 件 人">
							<el-input v-model="delivery.acceptName" placeholder="必填，收货人的姓名"></el-input>
						</el-form-item>
						<el-form-item prop="mobile" label="手机号码">
							<el-input v-model="delivery.mobile" placeholder="必填，收货人的手机号码"></el-input>
						</el-form-item>
						<el-form-item prop="telPhone" label="固定电话">
							<el-input v-model="delivery.telPhone" placeholder="可空，收货人固定电话号码"></el-input>
						</el-form-item>
						<el-form-item label="收货地区">
							<el-row class="select-list">
								<el-col :xs="24" :sm="8">
									<el-form-item prop="province">
										<el-select v-model="delivery.province" @change="handleProvinceChange" placeholder="请选择省份">
											<el-option v-for="item in provinceList"
												:key="item.id"
												:label="item.title"
												:value="item.title">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="8">
									<el-form-item prop="city">
										<el-select v-model="delivery.city" @change="handleCityChange" placeholder="请选择城市">
											<el-option v-for="item in cityList"
												:key="item.id"
												:label="item.title"
												:value="item.title">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="8">
									<el-form-item prop="area">
										<el-select v-model="delivery.area" placeholder="请选择地区">
											<el-option v-for="item in areaList"
												:key="item.id"
												:label="item.title"
												:value="item.title">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row>
						</el-form-item>
						<el-form-item prop="address" label="详细地区">
							<el-input v-model="delivery.address" placeholder="必填，除省市区外的详细地区"></el-input>
						</el-form-item>
						<el-form-item prop="expressId" label="物流公司">
							<el-select v-model="delivery.expressId" placeholder="请选择...">
								<el-option v-for="item in expressList"
									:key="item.id"
									:label="item.title"
									:value="item.id">
								</el-option>
							</el-select>
						</el-form-item>
						<el-form-item prop="expressCode" label="物流单号">
							<el-input v-model="delivery.expressCode" placeholder="必填，物流快递的单号"></el-input>
						</el-form-item>
						<el-form-item prop="freight" label="配送运费">
							<el-input v-model="delivery.freight" placeholder="必填，本次配送运费">
								<template slot="prepend">
									￥
								</template>
								<template slot="append">
									元
								</template>
							</el-input>
						</el-form-item>
						<el-form-item prop="remark" label="单据备注">
							<el-input type="textarea" :rows="3" v-model="delivery.remark" maxlength="512" show-word-limit placeholder="可空，发货单备注说明"></el-input>
						</el-form-item>
					</el-form>
				</el-card>


			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" icon="el-icon-edit" @click="submitDeliveryDialog">确 定</el-button>
				<el-button type="warning" @click="showDeliveryDialog = false">取 消</el-button>
			</div>
		</el-dialog>

		<el-dialog title="打印订单" :visible.sync="showPrintDialog" fullscreen>
			<div id="printContent" style="line-height:24px;">
				<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0" style="font-size:12px; font-family:'微软雅黑'; background:#fff;">
					<tr>
						<td width="40%" height="50" valign="top" style="font-size:20px;">NO.{{model.id}} 订单详情</td>
						<td width="30%">
							订单号：{{model.orderNo}}<br />
							日&nbsp;&nbsp; 期：{{model.addTime}}
						</td>
						<td width="30%">
							操&nbsp; 作 人：{{merchantInfo.userName}}<br />
							打印时间：{{new Date().toLocaleDateString()}}
						</td>
					</tr>
					<tr>
						<td colspan="3" style="padding:10px 0; border-top:1px solid #000;">
							<table width="100%" border="0" cellspacing="0" cellpadding="5" style="font-size:12px; font-family:'微软雅黑'; background:#fff;">
								<tr>
									<td align="left" width="50%" style="background:#ccc;">商品信息</td>
									<td width="10%" align="center" style="background:#ccc;">销售价</td>
									<td width="10%" align="center" style="background:#ccc;">优惠价</td>
									<td width="10%" align="center" style="background:#ccc;">数量</td>
									<td width="10%" align="center" style="background:#ccc;">合计</td>
									<td width="10%" align="center" style="background:#ccc;">状态</td>
								</tr>
								<tr v-for="(item,index) in model.orderGoods" :key="index">
									<td valign="top">
										{{item.goodsTitle}}<br />
										{{item.skuText}}
									</td>
									<td align="center" valign="top">￥{{item.goodsPrice}}</td>
									<td align="center" valign="top">￥{{item.realPrice}}</td>
									<td align="center" valign="top">{{item.quantity}}</td>
									<td align="center" valign="top">￥{{item.realPrice*item.quantity}}</td>
									<td align="center" valign="top">{{item.deliveryStatus===0?"未发货":item.deliveryStatus===1?"已发货":"已退货"}}</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="3" style="border-top:1px solid #000;">
							<table width="100%" border="0" cellspacing="0" cellpadding="5" style="margin:5px auto; font-size:12px; font-family:'微软雅黑'; background:#fff;">
								<tr>
									<td width="40%">
										会员账户：{{model.userName}}
									</td>
									<td width="60%">客户姓名：{{model.acceptName}}<br /></td>
								</tr>
								<tr>
									<td valign="top">支付方式：</td>
									<td>送货地址：{{model.address}}<br /></td>
								</tr>
								<tr>
									<td>配送方式：{{model.delivery.title}}</td>
									<td valign="top">手&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 机：{{model.mobile}}</td>
								</tr>
								<tr>
									<td>收货时间：{{model.acceptTime?model.acceptTime:"随时可配送"}}</td>
									<td valign="top">固定电话：{{model.telPhone}}</td>
								</tr>
								<tr>
									<td valign="top">订单备注：{{model.remark}}</td>
									<td valign="top">
										用户留言：{{model.postscript}}
									</td>
								</tr>
							</table>
							<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" style="border-top:1px solid #000; font-size:12px; font-family:'微软雅黑'; background:#fff;">
								<tr>
									<td align="right">商品金额￥{{model.realAmount}} + 配送费￥{{model.realFreight}} - 优惠券￥{{model.couponAmount}} - 促销￥{{model.promotionAmount}} = 订单总额￥{{model.orderAmount}}</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" icon="el-icon-printer" @click="submitPrintDialog">确 定</el-button>
				<el-button type="warning" @click="showPrintDialog = false">取 消</el-button>
			</div>
		</el-dialog>
		
		<div class="footer-box">
			<div class="footer-btn">
				<el-button type="primary" @click="deliveryDialogOpen" v-if="model.status===2">去发货</el-button>
				<el-button type="primary" @click="orderReceipt" v-if="model.status===3">去签收</el-button>
				<el-button type="warning" @click="orderInvalid" v-if="model.status!=7">作 废</el-button>
				<el-button type="success" @click="showPrintDialog=true" v-if="model.status>1">打 印</el-button>
				<el-button plain @click="$common.back()">返回上一页</el-button>
			</div>
		</div>
	</dt-main-body>
</template>

<script>
	export default {
		props: {
			id: 0
		},
		data() {
			return {
				activeName: 'info', //当前选项卡
				labelPosition: 'right', //表单对齐方式
				showDeliveryDialog: false,//发货窗口
				showPrintDialog: false, //打印窗口
				orderDeliveryList: [],//订单发货列表
				orderRefundList: [],//退款列表
				orderExchangeList: [],//换货列表
				expressList: [],//物流公司
				provinceList: [],//省份列表
				cityList: [],//城市列表
				areaList: [],//地区列表
				couponList: [],//优惠券列表
				merchantInfo: {},
				model: {
					id: 0,
					orderNo: null,
					userName: null,
					payableFreight: 0,
					payableAmount: 0,
					realAmount: 0,
					couponAmount: 0,
					promotionAmount: 0,
					frontAmount: 0,
					orderAmount: 0,
					paymentStatus: 0,
					deliveryStatus: 0,
					status: 1,
					exp: null,
					point: null,
					retainStartTime: null,
					retainEndTime: null,
					paymentTime: null,
					deliveryTime: null,
					addTime: null,
					completeTime: null,
					orderGoods: [],
					orderLog: [],
					orderPromotion: [],
					collectionRelations: [],
					payment: {},
					delivery: {},
					merchantId: null,
					orderType: null,
					activeId: 0,
					userId: null,
					deliveryId: null,
					acceptName: null,
					telPhone: null,
					mobile: null,
					province: null,
					city: null,
					area: null,
					address: null,
					realFreight: null,
					discountAmount: 0,
					isInsure: 0,
					insurePrice: 0,
					postscript: null,
					remark: null,
					acceptTime: null,
					useCouponId: null,
				},
				delivery: {
					id: 0,
					merchantId: null,
					orderId: null,
					orderNo: null,
					acceptName: null,
					telPhone: null,
					mobile: null,
					province: null,
					city: null,
					area: null,
					address: null,
					freight: null,
					expressId: null,
					expressCode: null,
					remark: null,
					addTime: null,
					deliveryGoods: []
				},
				rules: {
					acceptName: [
						{ required: true, message: '请输入收货人姓名', trigger: 'blur' }
					],
					mobile: [
						{ required: true, message: '请输入收货人手机号码', trigger: 'blur' },
						{ pattern: /^1[0-9]{10}$/, message: '手机号码格式不正确', trigger: 'blur' }
					],
					provinceId: [
						{ required: true, message: '请选择配送省份', trigger: 'change' }
					],
					cityId: [
						{ required: true, message: '请选择配送城区', trigger: 'change' }
					],
					areaId: [
						{ required: true, message: '请选择配送地区', trigger: 'change' }
					],
					address: [
						{ required: true, message: '请输入除省市区外收货地址', trigger: 'blur' }
					],
					freight: [
						{ required: true, message: '请输入本次配送物流的费用', trigger: 'blur' },
						{ pattern: /^(([0-9]|([1-9][0-9]{0,9}))((\.[0-9]{1,2})?))$/, message: '请输入正确金额，可保留两位小数', trigger: 'blur' }
					],
					expressId: [
						{ required: true, message: '请选择物流公司', trigger: 'change' }
					],
					expressCode: [
						{ required: true, message: '请输入物流单号', trigger: 'change' }
					],
				}
			}
		},
		methods: {
			//初始化数据
			async initData() {
				let _this = this; //当前页面
				if (!_this.id) {
					_this.$alert('参数有误，找不到订单信息。', '错误提示', {
						confirmButtonText: '确定',
						callback: action => {
							_this.$common.back();
						}
					});
					return false;
				}
				//订单信息
				await _this.$api.request({
					url: '/merchant/order/' + _this.id,
					loading: true,
					success(res) {
						//赋值给model
						Object.keys(_this.model).forEach(key => { _this.model[key] = res.data[key] });
					}
				});
				//赋值给发货记录表
				_this.$api.request({
					url: '/merchant/order/delivery/view/0?orderNo=' + encodeURI(_this.model.orderNo),
					success(res) {
						_this.orderDeliveryList = res.data;
					}
				});
				//赋值退款记录列表
				_this.$api.request({
					url: '/merchant/order/refund/view/1/0?orderNo=' + encodeURI(_this.model.orderNo),
					success(res) {
						_this.orderRefundList = res.data;
					}
				});
				//赋值换货记录列表
				_this.$api.request({
					url: '/merchant/order/refund/view/2/0?orderNo=' + encodeURI(_this.model.orderNo),
					success(res) {
						_this.orderExchangeList = res.data;
					}
				});
				//获取优惠券列表
				_this.$api.request({
					url: '/merchant/shop/coupon/history/view/0?orderNo=' + encodeURI(_this.model.orderNo),
					success(res) {
						_this.couponList = res.data;
					}
				});
				//获取当前管理员信息
				_this.$api.request({
					url: '/merchant',
					success(res) {
						_this.merchantInfo = res.data
					}
				});
			},
			//签收订单
			orderReceipt() {
				let _this = this; //当前页面
				//执行操作
				_this.$confirm('确认要签收该订单吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(function () {
					_this.$api.request({
						method: 'put',
						url: '/merchant/order/receipt/' + _this.model.id,
						loading: true,
						successMsg: '订单已签收成功',
						success(res) {
							_this.initData();//重新加载列表
						}
					})
				}).catch(function () { });
			},
			//作废订单
			orderInvalid() {
				let _this = this; //当前页面
				//执行操作
				_this.$confirm('确认要作废该订单吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(function () {
					_this.$api.request({
						method: 'put',
						url: '/merchant/order/invalid/' + _this.model.id,
						loading: true,
						successMsg: '订单作废已成功',
						success(res) {
							_this.initData();//重新加载列表
						}
					})
				}).catch(function () { });
			},
			//显示发货窗口
			deliveryDialogOpen() {
				let _this = this;
				if (_this.model.deliveryStatus == 1) {
					_this.$message({ type: 'warning', message: '订单已完成发货，无需此操作' });
					return false;
				}
				//加载省份列表
				_this.$api.request({
					url: '/client/area/view/0',
					success(res) {
						_this.provinceList = res.data;
					}
				});
				//加载物流列表
				_this.$api.request({
					url: '/client/shop/express/view/0',
					success(res) {
						_this.expressList = res.data;
					}
				});
				_this.delivery.merchantId = _this.model.merchantId;
				_this.delivery.orderId = _this.model.id;
				_this.delivery.orderNo = _this.model.orderNo;
				_this.delivery.acceptName = _this.model.acceptName;
				_this.delivery.telPhone = _this.model.telPhone;
				_this.delivery.mobile = _this.model.mobile;
				_this.delivery.province = _this.model.province;
				_this.delivery.city = _this.model.city;
				_this.delivery.area = _this.model.area;
				if (_this.model.province) {
					_this.handleProvinceChange(_this.delivery.province, _this.delivery.city)
				}
				if (_this.model.city) {
					_this.handleCityChange(_this.delivery.city, _this.delivery.area)
				}
				if (_this.model.address) {
					let addressArr = _this.model.address.split(",");
					_this.delivery.address = addressArr[addressArr.length - 1];
				}
				_this.delivery.freight = _this.model.realFreight;
				_this.delivery.deliveryGoods = [];

				_this.showDeliveryDialog = true;
			},
			//省份回调事件
			handleProvinceChange(val, city) {
				let _this = this;
				//加载城市列表
				_this.$api.request({
					url: '/client/area/view/0?keyword=' + encodeURI(val),
					success(res) {
						_this.cityList = res.data;
					},
					error(err) {
						_this.cityList = [];
					},
					complete() {
						if (!city) {
							_this.delivery.city = null;
							_this.delivery.area = null;
							_this.areaList = [];
						}
					}
				});
			},
			//城市回调事件
			handleCityChange(val, area) {
				let _this = this;
				//加载城市列表
				_this.$api.request({
					url: '/client/area/view/0?keyword=' + encodeURI(val),
					success(res) {
						_this.areaList = res.data;
					},
					error(err) {
						_this.areaList = []
					},
					complete() {
						if (!area) {
							_this.delivery.area = null;
						}
					}
				});
			},
			//设置不可选中的商品
			checkSelecGoods(row) {
				return row.deliveryStatus == 0;
			},
			//选中第几行商品
			handleDeliveryChange(val) {
				let _this = this;
				_this.delivery.deliveryGoods = [];
				val.map((item, index) => {
					_this.delivery.deliveryGoods.push({
						id: 0,
						deliveryId: 0,
						orderGoodsId: item.id
					});
				});
			},
			//提交确认发货
			submitDeliveryDialog() {
				let _this = this; //当前页面
				//多个表单验证
				const f1 = new Promise((resolve, reject) => {
					_this.$refs['deliveryForm'].validate((valid) => {
						if (valid) resolve()
					});
				});
				Promise.all([f1]).then(() => {
					//检查是否选择商品
					if (_this.delivery.deliveryGoods.length == 0) {
						_this.$message({ type: 'warning', message: '操作有误，请选择发货的商品' });
						return false;
					}
					//提交表单
					_this.$api.request({
						method: 'post',
						url: '/merchant/order/delivery',
						data: _this.delivery,
						loading: true,
						successMsg: '订单发货已成功',
						success(res) {
							_this.initData();
							_this.showDeliveryDialog = false;
						}
					});
				})
			},
			//确认打印订单
			submitPrintDialog() {
				var oWin = window.open("", "_blank");
				oWin.document.write(document.getElementById("printContent").innerHTML);
				oWin.focus();
				oWin.document.close();
				oWin.print();
				oWin.close();
				this.showPrintDialog = false;
				return false;
			},
			//返回收款状态
			checkPaymentStatus(status, beginDateStr, endDateStr) {
				if(status==1) {
					var curDate = new Date(),
					beginDate = new Date(beginDateStr),
					endDate = new Date(endDateStr);
					if (curDate < beginDate) {
						return '未开始';
					}
					if (curDate > endDate) {
						return '已超时';
					}
					return '待付款';
				}else if(status==2) {
					return '已付款';
				}else{
					return '已取消';
				}
			},
		},
		created() {
			this.initData();
		}
	}
</script>

<style lang="scss">
	.desctable {
		margin: auto 10px;
		.el-descriptions-item__label {
			color: #99a9bf;
		}
	}
</style>